FROM {{ namespace }}/{{ image_prefix }}openstack-base:{{ tag }}
{% block labels %}
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"
{% endblock %}

{% block panko_base_header %}{% endblock %}

{% import "macros.j2" as macros with context %}

{{ macros.configure_user(name='panko') }}

{% if install_type == 'binary' %}
    {% if base_package_type == 'rpm' %}

        {% set panko_base_packages = [
            'httpd',
            'mod_ssl',
            'openstack-panko-common',
            'python3-ldappool',
            'python3-mod_wsgi'
        ] %}
{{ macros.install_packages(panko_base_packages | customizable("packages")) }}
RUN sed -i -r 's,^(Listen 80),#\1,' /etc/httpd/conf/httpd.conf \
    && sed -i -r 's,^(Listen 443),#\1,' /etc/httpd/conf.d/ssl.conf
    {% elif base_package_type == 'deb' %}
        {% set panko_base_packages = [
                'apache2',
                'libapache2-mod-wsgi-py3'
        ] %}
{{ macros.install_packages(panko_base_packages | customizable("packages")) }}
RUN echo > /etc/apache2/ports.conf
    {% endif %}
{% elif install_type == 'source' %}
    {% if base_package_type == 'rpm' %}

       {% set panko_base_packages = [
            'httpd',
            'mod_ssl',
            'python3-ldappool',
            'python3-mod_wsgi'
        ] %}
{{ macros.install_packages(panko_base_packages | customizable("packages")) }}
RUN sed -i -r 's,^(Listen 80),#\1,' /etc/httpd/conf/httpd.conf \
    && sed -i -r 's,^(Listen 443),#\1,' /etc/httpd/conf.d/ssl.conf

    {% elif base_package_type == 'deb' %}

       {% set panko_base_packages = [
            'apache2',
            'libapache2-mod-wsgi-py3',
            'python3-ldappool'
        ] %}

{{ macros.install_packages(panko_base_packages | customizable("packages")) }}
RUN truncate -s 0 /etc/apache2/ports.conf

   {% endif %}
ADD panko-base-archive /panko-base-source

{% set panko_base_pip_packages = [
    '/panko',
    'pymongo'
] %}

RUN ln -s panko-base-source/* panko \
    && {{ macros.install_pip(panko_base_pip_packages | customizable("pip_packages")) }} \
    && mkdir -p /etc/panko \
    && cp -r /panko/etc/panko/* /etc/panko/ \
    && chown -R panko: /etc/panko

{% endif %}

COPY extend_start.sh /usr/local/bin/kolla_extend_start

RUN touch /usr/local/bin/kolla_panko_extend_start \
    && chmod 755 /usr/local/bin/kolla_extend_start /usr/local/bin/kolla_panko_extend_start

{% block panko_base_footer %}{% endblock %}
